#include <cstdio>
#include <cstring>
#include <cstdlib>
const int MAXN = 1000;
struct hugenum{
    int bit[MAXN];
    int len;//记录大整数的长度
};
hugenum bigone, bigtwo;
void strtonum(hugenum &big, char *s)
{//完成转换工作，这里要改变结构体当中的数据，必须要用引用，或者传地址
    big.len = strlen(s);
    for(int i = 0; i < big.len; ++i)
    {
        big.bit[i] = s[i] - '0';
    }
}
hugenum divide(hugenum big, int num, int &r)
{
    r = 0;
    hugenum tmp;
    int ttt;
    int quotient;
    bool flag = false;//用来标记遍历到第一个商不为零的运算
    for(int i = 0, j; i < big.len; ++i)
    {
        quotient = (big.bit[i] + r * 10) / num;
        r = (big.bit[i] + r * 10) % num;
        if(flag)
        {
            tmp.bit[j++] = quotient;
        }else{
            if(quotient != 0)
            {//遇到第一个不为零的商
                ttt = i;
                flag = true;
                tmp.bit[j++] = quotient;
            }
        }
    }
    tmp.len = big.len - ttt;
    return tmp;
}
    main()
{
    char s[MAXN];
    scanf("%s", s);
    int B;
    scanf("%d", &B);
    strtonum(bigone, s);
    int R;//用于保存余数
    bigtwo = divide(bigone, B, R);
    for(int i = 0; i < bigtwo.len; ++i)
    {
        printf("%d",bigtwo.bit[i]);
    }
    if(0 == bigtwo.len)
    {//不能有不输出数字的情况
        putchar('0');
    }
    putchar(' ');
    printf("%d\n", R);
    return 0;
}